README for Newton program "RPMDemo1"       Robert P. Munafo, 1993 August 29

RPMDemo1 is a sample Newton program posted in source form as an example for
aspiring Newton programmers.  It demonstrates techniques for the following:

- Show two floaters (protoFloatNGo views)
- Each floater allows the user to input text by writing in a protoInputLine
  field inside the floater.
+ Each floater can be dragged by starting at any point in the floater that is
  not inside the protoInputLine.
* When dragged, the floater moves to the front and the other objects on the
  screen are redrawn properly.
- When information in either floater is changed, the main view updates its
  display.  Specifically, the text entered in the first floater is repeated N
  times, where N is determined by a number entered in the second floater.
- Input fields use two undocumented font styles (tsCondense and tsShadow).

Item "+" was non-trivial.  The typical approach (using a viewClickScript in the
floater's template to do the dragging) doesn't work because it ends up catching
clicks that come from the protoInputLine; this causes the protoInputLine to
drag and to not accept written input.

The solution to that was to use the protoStaticText field, a sibling of the
protoInputLine, to catch clicks and pass a Drag message to its parent.

The proper redrawing (item "*") was by far the most non-intuitive.  Simply
creating two protoFloatNGo views and allowing them to be dragged doesn't work
-- whichever view is in front gets drawn properly all the time, but the other
floater doesn't get drawn properly if it is partly covered by the first
floater and is then dragged.

The solution for this is to bring the floater to the front before dragging. 
This is accomplished by the following:

  theFloater:Hide();
  theFloater:Show();
  theFloater:Dirty();
  RefreshViews();

The last two lines can be left out if you have defined a viewEffect for your
floater.  To illustrate the difference between a viewEffect and the
Dirty()/RefreshViews() method, the two floaters are done in two different
ways. The text floater ("Say what?") uses viewEffect, and the number
floater ("How many times?") uses Dirty()/RefreshViews().  You will probably
notice that the "Say what?" floater responds faster.

Useful things to note:

- The word and count are remembered when you close and re-open the application
(but not across reboots) because the application's view frame stays in memory. 
However, all child views are deleted -- so it does not remember the positions
of the floaters.

- The function which generates the text by repeating the word N times uses a
log(N) algorithm for speed.  The method used is to start with a single
occurrance of the word, then to repeatedly double and add one if the next bit
in the count is set.  It's kind of analagous to the "Russian peasant"
multiplication method.  (If I had used a simple "for i:=1 to count do" loop it
would have been *much* slower when the count is in the hundreds or thousands.)

- I have tried the undocumented "condensed" font style with different sizes,
and it doesn't seem to work.  It works with 14, though, probably because 14
is available as a "bitmap font" in the Newton.  This is probably why the
condensed style is not documented.
